package com.xujl.fastlib.base;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public abstract class BaseModule extends ReactContextBaseJavaModule {

    protected ReactApplicationContext context;

    public BaseModule (ReactApplicationContext reactContext) {
        super(reactContext);
        context = reactContext;
    }

    /**
     * @param eventName
     * @param params
     */
    public void sendEvent (String eventName, Object params) {
        context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    }

    protected String getValue (String key, ReadableMap map) {
        return (map != null && map.hasKey(key)) ? map.getString(key) : null;
    }

    @Override
    public boolean canOverrideExistingModule () {
        return super.canOverrideExistingModule();
    }
}
